package com.petter.security.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author : GD
 * @date :2022/3/1 : 22:36
 */
@Component
public class MyBeanPostProcessor implements BeanPostProcessor {

    private static int beforeCount = 0;
    private static int afterCount = 0;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        beforeCount ++;
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        afterCount ++;
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }

    public void printCount(){
        System.out.println(beforeCount);
        System.out.println(afterCount);
    }

}
